**First need to set FRED key
//set fredkey 

******************************************************************************
*Long-run inflation projection in Statement of Econonomic Projections
******************************************************************************

/*
 Longer Run FOMC Summary of Economic Projections for the Personal Consumption Expenditures Inflation Rate, 
 Central Tendency, Midpoint (PCECTPICTMLR)
 Frequency: FOMC Meetings
*/

local today=c(current_date)

*Download the data
import fred PCECTPICTMLR, clear

drop datestr
rename daten date 
rename *, lower

*Save data as an Excel with today's date in name
export excel "../data/fred/raw_data/pcectpictmlr_`today'.xlsx", replace firstrow(variables)

rename pcectpictmlr pcelr

*Generate FOMC meeting indicator
generate fomc_meet = 1

label variable fomc_meet "Dummy for FOMC Meetings"


compress 
save "../data/fred/clean_data/inflation_projections.dta", replace


******************************************************************************
*All other variables
******************************************************************************

*************************
* Daily variables
*************************

*Download the data
import fred DGS10 DGS3MO USRECD, clear

drop datestr
rename daten date 
rename *, lower

*Save data as an Excel with today's date in name
export excel "../data/fred/raw_data/daily_`today'.xlsx", replace firstrow(variables)

*Generate slope: 10y yield minus 3month yield
generate slope = dgs10 - dgs3mo
drop dgs10 dgs3m 

*Replace missing with past values 
sort date
replace slope = slope[_n-1] if missing(slope)

*************************
* Monthly variables
*************************

preserve 
	*Download the data
	import fred BBKMLEIX CFNAI, clear
	
	*Monthly indicator
	generate ym = mofd(daten)
	format ym %tm
	order ym
	drop datestr daten

	rename *, lower
	
	*Save data as an Excel with today's date in name
	export excel "../data/fred/raw_data/monthly_`today'.xlsx", replace firstrow(variables)	
	
	*Lag the monthly indices
	generate lagged_bbkmleix = bbkmleix[_n-1]
	generate lagged_cfnai = cfnai[_n-1]
	
	keep ym lagged*
	
	tempfile monthly_variables
	save 	`monthly_variables'
restore 

*Monthly indicator
generate ym = mofd(date)
format ym %tm

*Merge monthly with daily
merge m:1 ym using `monthly_variables', nogen 
drop ym

*Impose some sample filter
keep if date >= td(01jan1970)

label variable slope "Treasury slope (10-year minus 3-month) (FRED)"
label variable lagged_bbkmleix "One month lagged Brave-Butters-Kelley Leading Index (FRED)"
label variable lagged_cfnai	"One month lagged Chicago Fed National Activity Index (FRED)"

compress
save "../data/fred/clean_data/all_variables.dta", replace